package com.yet.container.loader;

import java.util.List;

import com.yet.container.registry.RegistryMeta.Address;
import com.yet.container.registry.RegistryMeta.ServiceMeta;
import com.yet.listener.RegistryEvent;
import com.yet.rule.Rule;

/**
 * 从注册中心抓取信息 1>启动的时候会将远程的服务抓到本地 2>监听注册中心节点并决定是否重新拉取
 */
public abstract class ServicesLoader {

	public abstract String getName();

	public abstract List<Address> lookupAddresses(ServiceMeta meta);

	public abstract Rule getRule(String args);

	public abstract void fetchSocketAddress();

	/**
	 * 负载均衡
	 */
	public Address getLoadBlanceAddress(ServiceMeta meta) {
		List<Address> lookupAddresses = lookupAddresses(meta);
		return getRule(null).getLoadBlanceAddress(meta, lookupAddresses);
	};

	public void init() {
	};

	public void destroy() {
	};

	public void onRegistryEvent(RegistryEvent registryEvent) {
		destroy();
		fetchSocketAddress();
	}
}
